import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    perms: ['GET /aaa','POST /bbb']     will control the page perms (you can set multiple perms)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: {
          title: '首页',
          icon: 'dashboard',
          noCache: true
        }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/goods',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'goodsManage',
    meta: {
      title: '商品管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'category',
        component: () => import('@/views/goods/category'),
        name: 'category',
        meta: {
          perms: [
            'GET /admin/category/list',
            'POST /admin/category/create',
            'GET /admin/category/read',
            'POST /admin/category/update',
            'POST /admin/category/delete'
          ],
          title: '商品类目',
          noCache: true
        }
      },
      {
        path: 'list',
        component: () => import('@/views/goods/list'),
        name: 'goodsList',
        meta: {
          perms: ['GET /admin/goods/list', 'POST /admin/goods/delete'],
          title: '商品列表',
          noCache: true
        }
      },
      {
        path: 'create',
        component: () => import('@/views/goods/create'),
        name: 'goodsCreate',
        meta: {
          perms: ['POST /admin/goods/create'],
          title: '新建商品',
          noCache: false
        }
      },
      {
        path: 'edit',
        component: () => import('@/views/goods/edit'),
        name: 'goodsEdit',
        meta: {
          perms: [
            'GET /admin/goods/detail',
            'POST /admin/goods/update',
            'POST /admin/goods/catAndBrand'
          ],
          title: '商品编辑',
          noCache: false
        },
        hidden: true
      }
    ]
  },
  {
    path: '/mall',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'mallManage',
    meta: {
      title: '订单管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'region',
        component: () => import('@/views/mall/region'),
        name: 'region',
        meta: {
          title: '行政区域',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'order',
        component: () => import('@/views/mall/order'),
        name: 'order',
        meta: {
          perms: [
            'GET /admin/order/list',
            'GET /admin/order/detail',
            'POST /admin/order/ordership',
            'POST /admin/order/orderrefund',
            'POST /admin/order/orderreply'
          ],
          title: '订单管理',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/store',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'storeManage',
    meta: {
      title: '门店管理',
      icon: 'chart'
    },
    children: [
      {
        path: '',
        component: () => import('@/views/store/list'),
        name: 'storeList',
        meta: {
          perms: ['GET /mms/v1/store/list'],
          title: '门店列表',
          noCache: true
        }
      },
      {
        path: 'classtimelist',
        component: () => import('@/views/store/classtimelist'),
        name: 'classtimelist',
        hidden: true,
        meta: {
          perms: ['GET /mms/v1/store/list'],
          title: '耗课统计',
          noCache: true
        }
      },
      {
        path: 'addShop',
        component: () => import('@/views/store/index'),
        name: 'addShop',
        meta: {
          perms: ['POST /mms/v1/store/save'],
          title: '添加门店',
          noCache: true
        }
      },
      {
        path: 'editShop',
        component: () => import('@/views/store/edit'),
        name: 'editShop',
        hidden: true,
        meta: {
          perms: ['POST /mms/v1/store/save'],
          title: '编辑门店',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/class',
    component: Layout,
    redirect: 'noredirect',
    name: 'classManage',
    alwaysShow: true,
    meta: {
      title: '班级管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'classList',
        component: () => import('@/views/class/list'),
        name: 'classList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '班级列表',
          noCache: true
        }
      },
      {
        path: 'classAdd',
        component: () => import('@/views/class/add'),
        name: 'classAdd',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '新建班级',
          noCache: true
        }
      },
      {
        path: 'classEdit',
        component: () => import('@/views/class/edit'),
        name: 'classEdit',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '编辑班级',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/teacher',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'teacherManage',
    meta: {
      title: '老师管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'teacherlist',
        component: () => import('@/views/teacher/list'),
        name: 'teacherlist',
        meta: {
          perms: ['GET /admin/stat/user'],
          title: '老师列表',
          noCache: true
        }
      },
      {
        path: 'addteacher',
        component: () => import('@/views/teacher/add'),
        name: 'addteacher',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '新建老师',
          noCache: true
        }
      },
      {
        path: 'editTeacher',
        component: () => import('@/views/teacher/editTeacher'),
        name: 'editTeacher',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '老师编辑',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'userManage',
    meta: {
      title: '学生管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/user/list'),
        name: 'user',
        meta: {
          perms: ['GET /admin/user/list'],
          title: '学生列表',
          noCache: true
        }
      },
      {
        path: 'managelist',
        component: () => import('@/views/user/managelist'),
        name: 'managelist',
        meta: {
          perms: ['GET /admin/user/list'],
          title: '充值记录',
          noCache: true
        }
      },
      {
        path: 'addUser',
        component: () => import('@/views/user/adduser'),
        name: 'addUser',
        meta: {
          perms: ['GET /admin/address/list'],
          title: '新建学生',
          noCache: true
        }
      },
      {
        path: 'editUser',
        component: () => import('@/views/user/editUser'),
        name: 'editUser',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '学生编辑',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'manageUser',
        component: () => import('@/views/user/manage'),
        name: 'manageUser',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '课次管理',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/discuss',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'discussManage',
    meta: {
      title: '作品管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'stuComment',
        component: () => import('@/views/discuss/stuComment'),
        name: 'stuComment',
        meta: {
          perms: ['GET /admin/comment/list', 'POST /admin/comment/delete'],
          title: '学生评价',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'teaComment',
        component: () => import('@/views/discuss/teaComment'),
        name: 'teaComment',
        meta: {
          perms: ['GET /admin/comment/list', 'POST /admin/comment/delete'],
          title: '学生作品',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/sys',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'sysManage',
    meta: {
      title: '系统管理',
      icon: 'chart'
    },
    hidden: true,
    children: [
      {
        path: 'admin',
        component: () => import('@/views/sys/admin'),
        name: 'admin',
        meta: {
          perms: [
            'GET /admin/admin/list',
            'POST /admin/admin/create',
            'POST /admin/admin/update',
            'POST /admin/admin/delete'
          ],
          title: '管理员',
          noCache: true
        }
      },
      {
        path: 'log',
        component: () => import('@/views/sys/log'),
        name: 'log',
        meta: {
          perms: ['GET /admin/log/list'],
          title: '操作日志',
          noCache: true
        }
      },
      {
        path: 'role',
        component: () => import('@/views/sys/role'),
        name: 'role',
        meta: {
          perms: [
            'GET /admin/role/list',
            'POST /admin/role/create',
            'POST /admin/role/update',
            'POST /admin/role/delete',
            'GET /admin/role/permissions',
            'POST /admin/role/permissions'
          ],
          title: '角色管理',
          noCache: true
        }
      },
      {
        path: 'os',
        component: () => import('@/views/sys/os'),
        name: 'os',
        meta: {
          perms: [
            'GET /admin/storage/list',
            'POST /admin/storage/create',
            'POST /admin/storage/update',
            'POST /admin/storage/delete'
          ],
          title: '对象存储',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/video',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'videoManage',
    meta: {
      title: '视频管理',
      icon: 'chart'
    },
    hidden: true,
    children: [
      {
        path: 'videoList',
        component: () => import('@/views/video/list'),
        name: 'videoList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '视频列表',
          noCache: true
        }
      },
      {
        path: 'videoEdit',
        component: () => import('@/views/video/edit'),
        name: 'videoEdit',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '视频编辑',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'videoAdd',
        component: () => import('@/views/video/add'),
        name: 'videoAdd',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '视频添加',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/course',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'courseManage',
    meta: {
      title: '课程管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'courseList',
        component: () => import('@/views/course/list'),
        name: 'courseList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '课程列表',
          noCache: true
        }
      },
      {
        path: 'courseAdd',
        component: () => import('@/views/course/add'),
        name: 'courseAdd',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '课程添加',
          noCache: true
        }
      },
      {
        path: 'courseEdit',
        component: () => import('@/views/course/edit'),
        name: 'courseEdit',
        hidden: true,
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '课程编辑',
          noCache: true
        }
      },
      {
        path: 'courseCategory',
        component: () => import('@/views/course/courseCategory'),
        name: 'courseCategory',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '课程分类',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/operation',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'courseManage',
    meta: {
      title: '运营管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'bannerList',
        component: () => import('@/views/operation/bannerList'),
        name: 'bannerList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '轮播列表',
          noCache: true
        }
      },
      {
        path: 'bannerAdd',
        component: () => import('@/views/operation/bannerAdd'),
        name: 'bannerAdd',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '轮播添加',
          noCache: true
        }
      },
      {
        path: 'bannerEdit',
        component: () => import('@/views/operation/edit'),
        name: 'bannerEdit',
        hidden: true,
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '编辑轮播',
          noCache: true
        }
      }
    ]
  },

  {
    path: '/content',
    component: Layout,
    redirect: 'noredirect',
    name: 'contentManage',
    alwaysShow: true,
    meta: {
      title: '内容管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'contentList',
        component: () => import('@/views/content/list'),
        name: 'contentList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '内容列表',
          noCache: true
        }
      },
      {
        path: 'contentAdd',
        component: () => import('@/views/content/add'),
        name: 'contentAdd',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '新建内容',
          noCache: true
        }
      },
      {
        path: 'contentEdit',
        component: () => import('@/views/content/edit'),
        name: 'contentEdit',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '编辑内容',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/courseBooking',
    component: Layout,
    redirect: 'noredirect',
    name: 'courseBooking',
    meta: {
      icon: 'chart'
    },
    children: [
      {
        path: 'courseBookingList',
        component: () => import('@/views/courseBooking/courseBookingList'),
        name: 'courseBookingList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '课程预约管理',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/config',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'configManage',
    hidden: true,
    meta: {
      title: '配置管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'area',
        component: () => import('@/views/config/Area.vue'),
        name: 'area',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '运费模版配置',
          noCache: true
        }
      },
      {
        path: 'addArea',
        component: () => import('@/views/config/add.vue'),
        name: 'addArea',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '添加模版',
          noCache: true
        }
      },
      {
        path: 'editArea',
        component: () => import('@/views/config/edit.vue'),
        name: 'editArea',
        hidden: true,
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '编辑',
          noCache: true
        }
      }
      // {
      //   path: 'express',
      //   component: () => import('@/views/config/express'),
      //   name: 'configExpress',
      //   meta: {
      //     perms: ['GET /admin/config/express', 'POST /admin/config/express'],
      //     title: '运费配置',
      //     noCache: true
      //   }
      // },
      // {
      //   path: 'order',
      //   component: () => import('@/views/config/order'),
      //   name: 'configOrder',
      //   meta: {
      //     perms: ['GET /admin/config/order', 'POST /admin/config/order'],
      //     title: '订单配置',
      //     noCache: true
      //   }
      // },
      // {
      //   path: 'wx',
      //   component: () => import('@/views/config/wx'),
      //   name: 'configWx',
      //   meta: {
      //     perms: ['GET /admin/config/wx', 'POST /admin/config/wx'],
      //     title: '小程序配置',
      //     noCache: true
      //   }
      // }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    children: [
      {
        path: 'password',
        component: () => import('@/views/profile/password'),
        name: 'password',
        meta: {
          title: '修改密码',
          noCache: true
        }
      }
    ],
    hidden: true
  },

  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

export const asyncRouterMap2 = [
  {
    path: '/class',
    component: Layout,
    redirect: 'noredirect',
    name: 'classManage',
    alwaysShow: true,
    meta: {
      title: '班级管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'classList',
        component: () => import('@/views/class/list'),
        name: 'classList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '班级列表',
          noCache: true
        }
      },
      {
        path: 'classAdd',
        component: () => import('@/views/class/add'),
        name: 'classAdd',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '新建班级',
          noCache: true
        }
      },
      {
        path: 'classEdit',
        component: () => import('@/views/class/edit'),
        name: 'classEdit',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '编辑班级',
          noCache: true,
          hidden: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/teacher',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'teacherManage',
    meta: {
      title: '老师管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'teacherlist',
        component: () => import('@/views/teacher/list'),
        name: 'teacherlist',
        meta: {
          perms: ['GET /admin/stat/user'],
          title: '老师列表',
          noCache: true
        }
      },
      {
        path: 'addteacher',
        component: () => import('@/views/teacher/add'),
        name: 'addteacher',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '新建老师',
          noCache: true
        }
      },
      {
        path: 'editTeacher',
        component: () => import('@/views/teacher/editTeacher'),
        name: 'editTeacher',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '老师编辑',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'userManage',
    meta: {
      title: '学生管理',
      icon: 'chart'
    },
    children: [
      {
        path: 'list',
        component: () => import('@/views/user/list'),
        name: 'user',
        meta: {
          perms: ['GET /admin/user/list'],
          title: '学生列表',
          noCache: true
        }
      },
      {
        path: 'addUser',
        component: () => import('@/views/user/adduser'),
        name: 'addUser',
        meta: {
          perms: ['GET /admin/address/list'],
          title: '新建学生',
          noCache: true
        }
      },
      {
        path: 'editUser',
        component: () => import('@/views/user/editUser'),
        name: 'editUser',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '学生编辑',
          noCache: true
        },
        hidden: true
      },
      {
        path: 'manageUser',
        component: () => import('@/views/user/manage'),
        name: 'manageUser',
        meta: {
          perms: ['GET /admin/stat/order'],
          title: '课次管理',
          noCache: true
        },
        hidden: true
      }
    ]
  },
  {
    path: '/courseBooking',
    component: Layout,
    redirect: 'noredirect',
    name: 'courseBooking',
    meta: {
      icon: 'chart'
    },
    children: [
      {
        path: 'courseBookingList',
        component: () => import('@/views/courseBooking/courseBookingList'),
        name: 'courseBookingList',
        meta: {
          perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
          title: '课程预约管理',
          noCache: true
        }
      }
    ]
  },
  {
    path: '/store',
    component: Layout,
    redirect: 'noredirect',
    alwaysShow: true,
    name: 'storeManage',
    meta: {
      title: '门店管理',
      icon: 'chart'
    },
    children: [
      {
        path: '',
        component: () => import('@/views/store/list'),
        name: 'storeList',
        meta: {
          perms: ['GET /mms/v1/store/list'],
          title: '门店列表',
          noCache: true
        }
      },
      {
        path: 'classtimelist',
        component: () => import('@/views/store/classtimelist'),
        name: 'classtimelist',
        hidden: true,
        meta: {
          perms: ['GET /mms/v1/store/list'],
          title: '耗课统计',
          noCache: true
        }
      },
      {
        path: 'editShop',
        component: () => import('@/views/store/edit'),
        name: 'editShop',
        hidden: true,
        meta: {
          perms: ['POST /mms/v1/store/save'],
          title: '编辑门店',
          noCache: true
        }
      }
    ]
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]
